/*
 * Copyright (c) 2025, 廖树财, <study_2030@163.com>
 *
 * PEE2.0-YCYW-HY is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *         http://license.coscl.org.cn/MulanPSL2     
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
#pragma once
#include "iniparser.h"
#include "define.h"

// 实现MQTT端业务的相关

typedef (*PFUN_PRO_COMMON)(char *); //   c/s modol
typedef (*PFUN_PRO_REPORT)();       // report
// typedef (*PFUN_PRO_publish)(); // publish

/// TerminalManage
extern PFUN_PRO_COMMON g_pFunTerminalSyncTime; //
extern PFUN_PRO_COMMON g_pFunTerminalReboot;   //
extern PFUN_PRO_COMMON g_pFunTerminalSetConfig;
extern PFUN_PRO_COMMON g_pFunTerminalUpdate;
extern PFUN_PRO_COMMON g_pFunFirmwareDownload;
extern PFUN_PRO_COMMON g_pFunactionPatchDownload;
extern PFUN_PRO_COMMON g_pFunactionConfigDownalod;
extern PFUN_PRO_COMMON g_pFunactionConfigUpgrade;
extern PFUN_PRO_COMMON g_pFunFirmwareUpgrade;
extern PFUN_PRO_COMMON g_pFunTerminalLog;
extern PFUN_PRO_COMMON g_pFunTerminalLogLevel;
extern PFUN_PRO_COMMON g_pFunTerminalCallLinkTrace;
extern PFUN_PRO_COMMON g_pFunsetFullReport;
extern PFUN_PRO_COMMON g_pFundataSpaceService;
extern PFUN_PRO_COMMON g_pFunTerminalAppCommond;
extern PFUN_PRO_COMMON g_pFunTerminalConCommond;
extern PFUN_PRO_COMMON g_pFunTerminalDirCommond;
extern PFUN_PRO_COMMON g_pFunTerminalOTACommond;
extern PFUN_PRO_COMMON g_pFunSafeCommond;
extern PFUN_PRO_COMMON g_pFunVulnPolicy;
extern PFUN_PRO_COMMON g_pPwqualityConfig;
extern PFUN_PRO_COMMON g_pKpatchConfig;
extern PFUN_PRO_COMMON g_pFunTerminal_Init;
extern PFUN_PRO_COMMON g_pFunUsbPlugging;
extern PFUN_PRO_COMMON g_pFunStartDepend;
extern PFUN_PRO_COMMON g_pFunUpdateCer;
extern PFUN_PRO_COMMON g_pFunThirdModule;
extern PFUN_PRO_COMMON g_pFunSubDeviceAuth;
extern PFUN_PRO_COMMON g_pFunQueryScram;
extern PFUN_PRO_COMMON g_pFunPlcModule;
// SecurityManage
extern PFUN_PRO_COMMON g_pFunSecurityProc;
extern PFUN_PRO_COMMON g_pFunSecurityCommond;
extern PFUN_PRO_COMMON g_pFunpo_policy;
extern PFUN_PRO_COMMON g_pFunpo_setBaselineCheck;

// publish
extern PFUN_PRO_REPORT g_pFunTerminalPublish; // runtime report
extern PFUN_PRO_REPORT g_pFunLogPublish;      // log publish
extern PFUN_PRO_REPORT g_pFunTerminalManage;  // baseinfo report
extern PFUN_PRO_REPORT g_pFunConfManage;
extern PFUN_PRO_REPORT g_pFunrealTimeMonitoring;

// 网络延时测试
extern PFUN_PRO_COMMON g_pFunnetDelayTest;

void readMQTTClientCfg(dictionary *ini, ST_CLIENT_INFO *mqttClient);

//----------------可删除 start-----------------------
void Test_Logout();

void Test_updateDeviceStatusOnline(char *strDeviceId);

void Test_updateDeviceStatusOffline(char *strDeviceId);

void Test_DataReport(char *strDeviceId);

void Test_addSubDevice(char *strDeviceId);

void Test_deleteSubDevice(char *strDeviceId);

void Test_commandResponse(int mid);

void Test_queryDeviceInfo(char *pcNodeId);

void Test_CustomTopicReport(char *strDeviceId);

void Test_CustomTopicSubscribe();

/* int logincount = 0; */
void handleLoginSuccess(void *context, int messageId, int code, char *message);

void handleLoginFailure(void *context, int messageId, int code, char *message);

void handleConnectionLost(void *context, int messageId, int code, char *message);

void handleSubscribeSuccess(void *context, int messageId, int code, char *message);

void handleSubscribeFailure(void *context, int messageId, int code, char *message);

void handlePublishSuccess(void *context, int messageId, int code, char *message);

void handlePublishFailure(void *context, int messageId, int code, char *message);

void handleLogoutSuccess(void *context, int messageId, int code, char *message);

void handleLogoutFailure(void *context, int messageId, int code, char *message);

void handleCommandArrived(void *context, int messageId, int code, char *message);

void handleCustomTopicMessageArrived(void *context, int messageId, int code, const char *topic, char *message);

void JsonToStruct_DeviceAddRsp_my(const char *strJson);

void handleSubDeviceAddResult(void *context, int messageId, int code, char *message);

void handleSubDeviceDeleteResult(void *context, int messageId, int code, char *message);

void handleSubDeviceUpdateResult(void *context, int messageId, int code, char *message);

void handleDeviceQueryResult(void *context, int messageId, int code, char *message);

void Test_Login();

void setMyCallbacks();

//----------------可删除 end-----------------------

// mqtt 登录相关配置
void setLoginConfig();

void pthread_manage();

void setCallbacks(ST_MODEL_CTL st_model_ctl);

void handleBDLog(char *pBuf);

// 处理业务
void proMsg(char *top, char *buf, int size);

void terminalCmd();

void netDelayTest();
